Adding ICPC Live Archive
[andmenj-acm.git] / ICPC Live Archive / 4808 - Digits Count / 4808.2.cpp
blobbe81a0499e9dc5da3130c61ccb4bfabf8ab47d7c
1 using namespace std;
2 #include <algorithm>
3 #include <iostream>
4 #include <iterator>
5 #include <numeric>
6 #include <sstream>
7 #include <fstream>
8 #include <cassert>
9 #include <climits>
10 #include <cstdlib>
11 #include <cstring>
12 #include <string>
13 #include <cstdio>
14 #include <vector>
15 #include <cmath>
16 #include <queue>
17 #include <deque>
18 #include <stack>
19 #include <list>
20 #include <map>
21 #include <set>
23 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
27 int count(int x, int digit) {
28 int power = 1, ans = 0;
29 int left = x, right = 0;
30 while (left > 0) {
31 int current = left % 10;
32 left /= 10;
33 ans += left * power;
34 if (current == digit) {
35 ans += right + 1;
36 } else if (current > digit) {
37 ans += power;
39 power *= 10;
40 right = x % power;
42 if (digit == 0) {
43 ans -= (power - 1) / 9;
45 return ans;
48 int main(){
49 int a, b;
50 while (cin >> a >> b) {
51 if (a == 0 and b == 0) break;
52 int ans[10];
54 for (int d = 0; d <= 9; ++d) {
55 ans[d] = count(b, d);
56 if (a - 1 > 0) ans[d] -= count(a - 1, d);
59 for (int i = 0; i <= 9; ++i) {
60 if (i > 0) printf(" ");
61 printf("%d", ans[i]);
63 printf("\n");
67 return 0;